<!-- 索赔发票查询 （明细参照 索赔发票审核）-->
<template>
    <div>
 <TopFilter ref="TopFilterss" :list="topFilterInit" :cols="4" :collapse="collapse" labelWidth="110" @filterChange="changeHandle"></TopFilter>
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :fetchapi="fetchapi"
      :datakey="'records'"
      :onColumnsChange="columns => (this.columns = columns)"
      :is-select-column="false"
      :onRowSelectChange="selectChange"
      >
     
        <template slot="controls" slot-scope="props">
        <multiuse-button type="primary" :click="exportFileBtn.bind()">导出</multiuse-button>
      </template>
      </FilterTable>
      <BaseDialog :visible.sync="selectDelearFlag" :title="'经销商选择'" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
        <DealerList @close="Delearclose" @save="Delearsave"></DealerList>
      </BaseDialog>
        <Drawer :visible.sync="claimFlag" :title="'结算单明细'" width="60%" destroyOnClose :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}">
      <StatePage @close="claimClose"  :rowData="rowData" ></StatePage>
    </Drawer>

      </div>
</template>

<script>
import { getToken, getAppId, getUserId } from '@/assets/js/auth';
import moment from "moment";
import { dictionary } from '@/utils/dictMixin';
import DealerList from '@/pages/claimDemage/tools/DealerList.vue';
import {getListByPage, getListForExport,exporturl} from '@/api/claim/factory/StatementsSelect';
import { exportExcelFile } from '@/utils/index';
import StatePage from './StatePage.vue';
    export  default{
        mixins: [dictionary],
        components: {
        StatePage,DealerList
        },
        data(){
            return{
                topFilterInit: this.topFilterInitFun(),
                fetchParams: {xhrAbort: true},    
                selectDelearFlag: false,
                collapse: true,
                claimFlag:false,
                headersObj: {
                jwt: getToken(),
                appId: getAppId(),
                userId: getUserId(),
                userAgent: 'pc',
      },
                columns: this.creatHeader(),
                rowData: {},
                fetchapi: getListByPage
            };

        },
 created() {
    if(getAppId()=='beijing'){
      this.topFilterInit.find((x) => x.fieldName == 'carType').itemList = this.createDictList('5543');
    }else{
      this.topFilterInit.find((x) => x.fieldName == 'carType').itemList = this.createDictList('5543');
      this.topFilterInit.find((x) => x.fieldName == 'carType').initialValue = 55431002;
      this.topFilterInit.find((x) => x.fieldName == 'carType').disabled=true;
      
    }
  },
    methods:{
    claimClose() {
      this.claimFlag = false;
    },
    //选中
    selectChange(rows) {
    //   this.selectedRows = rows;
    //   this.disableds = this.selectedRows.length <= 0;
    //   console.log(this.selectedRows);
    },
    // 导出
   async exportFileBtn() {
      let json = Object.assign({}, { CODE: 'CODE_00000152' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }
      // getListForExport(this.fetchParams).then(res => {
      //   exportExcelFile(res.data, '索赔发票表');
      // });
    },
    SelectDelear() {
      this.selectDelearFlag = true;
    },//关闭
    Delearclose() {
      this.selectDelearFlag = false;
    },
    //保存
    Delearsave(obj) {
      this.topFilterInit.map(x => {
        if ('ownerCode' == x.fieldName) {
          x.initialValue = obj[0].dealerCode; //维修工单号返显
        }
      })
      this.selectDelearFlag = false;

    },
    showClaimNum(val) {
      this.rowData = val;
      this.claimFlag = true;
      console.log("!!!!!!!!!!!",this.rowData.batchId);
      // let res = await qryClaimById({id:row.batchId});
    },
    //搜索获取数据
    changeHandle(val) {
      /*刷新表格 用它*/
      this.fetchParams = Object.assign({}, this.fetchParams, val,{xhrAbort:false});
      console.log(this.fetchParams);
    },
    //搜索数据
    topFilterInitFun() {
      return [
        {
          type: 'INPUT',
          label: '服务站代码',
          fieldName: 'ownerCode',
          placeholder: '请输入',
          unitRender: p => {
            return (
              <div>
                <multiuse-button icon="el-icon-search" onClick={() => this.SelectDelear()} />
              </div>
            );
          }
        },
         {
          type: 'INPUT',
          label: '服务站名称',
          fieldName: 'dealerName',
          placeholder: '',
          initialValue: '',
          
        },
        { type: 'RANGE_DATE', label: '结算单生成时间', fieldName: 'statementGenerationTimeStar|statementGenerationTimeEnd', placeholder: '请输入', 
          initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ],
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }] },
        //{ type: 'RANGE_DATE', label: '结算单生成时间', fieldName: 'statementGenerationTimeStar|statementGenerationTimeEnd', placeholder: '请输入' },
        { type: 'RANGE_DATE', label: '发票到达时间', fieldName: 'invoiceReviewTimeStar|invoiceReviewTimeEnd', placeholder: '请输入',initialValue: [
            moment()
              .startOf('week')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('week')
              .format('YYYY-MM-DD HH:mm:ss')
          ] },
        // {
        //   type: 'SELECT',
        //   label: '发票状态',
        //   fieldName: 'invoiceStatus',
        //   placeholder: '请选择',
        //   itemList: this.createDictList('6071')
        // },
         { type: 'SELECT', label: '发票状态', fieldName: 'batchStatus', placeholder: '请选择结算单状态...', initialValue: '', itemList: this.createDictList('5548',[55481003,55481004,55481005])},
         {
          type: 'SELECT',
          label: '车辆属性',
          fieldName: 'carType',
          placeholder: '车辆属性...',
          initialValue: '',
          itemList:[],
          //rules: [{required: true, message: '请选择车辆属性...', trigger: 'change'}]
          },
        // {
        //   type: 'SELECT',
        //   label: '结算单状态',
        //   fieldName: 'settleStatus',
        //   disabled: false, // 只读
        //   initialValue: '',
        //   itemList: this.createDictList('5546'),
        // },
      ];
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
          {
          title: '操作',
          dataIndex: 'column-action',
          //width: 100,
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.showClaimNum(props.row)}>
                  查看明细
                </multiuse-button>
              </div>
            );
          }
        },
            { title: '车辆属性', dataIndex: 'carTypeStr', sorter: true, width: 120 },
            { title: '结算单号', dataIndex: 'settleNo', sorter: true },   
            {title: '结算单状态', dataIndex: 'statusStr', sorter: true},
            {title: '合计台数', dataIndex: 'hjts', sorter: true},
            {title: '开票金额', dataIndex: 'invoiceAmout', sorter: true, summation: true ,precision:2},
            {title: '开票净额', dataIndex: 'kpje', sorter: true, summation: true ,precision:2},
            {title: '税额', dataIndex: 'settleStatusStr', sorter: true },
            { title: '税率', dataIndex: 'taxRate', sorter: true },
            { title: '增减金额', dataIndex: 'zjje', sorter: true },
            {title: '服务站',dataIndex: 'dealerName',sorter: true},
            {title: '下线工厂',dataIndex: 'factName',sorter: true},
            {
          title: '录入日期',
          dataIndex: 'enteredDate',
          width: 150,
         dateFormat:'yyyy-MM-dd HH:mm:ss'
        }
         
        
      ];
    },
        }
    };
 </script>
<style lang="less" scoped></style>   
